home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / QUI / UTI / Premier Plug-In Kit 1.0.cpt / Premier Plug-In Kit 1.0 / MPW Examples / .c / Black & White.c < prev    next >
Text File  |  1992-03-04  |  2KB  |  66 lines

  1. //———————————————————————————————————————————————
  2. //
  3. //    ©1991 Adobe Systems Inc.
  4. //    written by Randy Ubillos
  5. //
  6. //———————————————————————————————————————————————
  7.  
  8. // Load in your Mac headers here
  9. #pragma load "headers.d"
  10.  
  11. #include "Interface-Filter.h"
  12.  
  13. // This is the external assembly code we use
  14. void BW(Ptr srcpix, Ptr dstpix, short height, short rowBytes, Ptr lookup, Ptr repeat);
  15.  
  16. //———————————————————————————————————————————————
  17. // Perform the effect
  18.  
  19. pascal short xFilter(short selector, VideoHandle theData)
  20. {
  21.     short                result = 0,height,rowbytes,i;
  22.     Rect                box;
  23.     Ptr                    srcpix,dstpix,lookptr,repeatptr;
  24.     unsigned char        *temp;
  25.     Handle                lookup,repeat;
  26.     long                *wide;
  27.     char                mode;
  28.  
  29.     switch (selector) {
  30.         case fsExecute:
  31.             if (!(lookup = Get1Resource('LKUP',100))) {                    // check for LKUP resource
  32.                 lookup = NewHandle(256 * 3);                            // if we don't have it,
  33.                 temp = *lookup;                                            // then build it
  34.                 for (i=0; i<256; i++) temp[i] = (long)i * 299L / 1000L;
  35.                 temp += 256;
  36.                 for (i=0; i<256; i++) temp[i] = (long)i * 587L / 1000L;    // this is for RGB to Gray
  37.                 temp += 256;
  38.                 for (i=0; i<256; i++) temp[i] = (long)i * 114L / 1000L;
  39.                 AddResource(lookup,'LKUP',100,"\p");
  40.                 WriteResource(lookup);
  41.             }
  42.             if (!(repeat = Get1Resource('REPT',100))) {                    // check for REPT resource
  43.                 repeat = NewHandle(256 * 4);                            // if we don't have one,
  44.                 wide = (long*)*repeat;                                    // then build it
  45.                 for (i=0; i<256; i++) wide[i] = (i<<16)+(i<<8)+i;        // this is used to replicate
  46.                 AddResource(repeat,'REPT',100,"\p");                    // a byte into all positions
  47.                 WriteResource(repeat);                                    // in a long word
  48.             }
  49.             box = (*theData)->destination->portRect;                    // find the rectangle
  50.             height = box.bottom - box.top;                                // and height and rowbytes
  51.             rowbytes = (*(*theData)->destination->portPixMap)->rowBytes & 0x3FFF;
  52.             
  53.             srcpix = GetPixBaseAddr((*theData)->source->portPixMap);    // find the buffer's bases
  54.             dstpix = GetPixBaseAddr((*theData)->destination->portPixMap);
  55.             lookptr = StripAddress(*lookup);
  56.             repeatptr = StripAddress(*repeat);                            // dereference the tables
  57.             mode = true32b;
  58.             SwapMMUMode(&mode);                                            // must swap to 32 bit mode
  59.             BW(srcpix,dstpix,height,rowbytes,lookptr,repeatptr);        // process the buffer
  60.             SwapMMUMode(&mode);                                            // swap back
  61.             break;
  62.     }
  63.     return(result);
  64. }
  65.  
  66.